(display "\n========================================\n")
(define dx 0.00001)

(define (devirative g)
    (lambda (x) (/ (- (g (+ x dx)) (g x)) dx)))

(define (newton-transform g)
    (lambda (x) (- x (/ (g x) ((devirative g) x)))))

(define (fix-point f guess)
    (define tolerance 0.00001)
    (define (good-enough? a b)
        (< (abs (- a b)) tolerance))
    (define (try guess)
        (let ((next (f guess)))
            (if (good-enough? next guess)
                next
                (try next))))
    (try guess))

(define (newtons-method g guess)
    (fix-point (newton-transform g) guess))

; (define (sqrt x)
;     (newtons-method (lambda (y) (- (square y) x)) 1.0))
; (display (sqrt 2))
(define (cubic a b c)
    (lambda (x) (+ (* x x x) (* a x x) (* b x) c)))

(display (newtons-method (cubic 2 1 0) -1))

(newline)
(display "\n========================================\n")
